package com.cat.DataStructure04;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/convert-to-base-2/
 * @create 2025/11/24 15:28
 * @since JDK17
 */

public class Solution03 {
    public String baseNeg2(int n) {
        if ((n & (n - 1)) == 0) {
            return String.valueOf(n);
        }
        long t = 0;
        String ans = String.valueOf(t);
        if (ans.length() % 2 == 1) {    // 奇数
            ans = "1" + ans;
        } else {
            ans = "10" + ans;
        }
        char[] arr = ans.toCharArray();
        int m = arr.length;
        for (int i = 0; i < m; i++) {   // 所有的正数
            if (i % 2 == 0) {
                t += 1l << (m - i);
            } else {
                t += 1l << (m - i);
            }
        }

        return new String(arr);
    }
}
